package karaokestrong.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;

import karaokestrong.excepcion.DAOExcepcion;
import karaokestrong.modelo.Cancion;
import karaokestrong.modelo.Reportes;
import karaokestrong.modelo.Evento;
import karaokestrong.util.ConexionBD;

public class ReportesDAO {
	
	
	public Collection<Reportes> buscarPorFeNo( Timestamp fecha, String nombre) throws DAOExcepcion {
		Collection<Reportes> c = new ArrayList<>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			String query = "Select loc.nombre as NombreS, comp.fecha, deta.cantidad, prod.nombre as NombreP, prod.precio from karaokestrong.comprobante as comp inner join karaokestrong.pedido as pedi on comp.idcomprobante=pedi.idcomprobante inner join karaokestrong.cliente as clie on pedi.idcliente=clie.idcliente inner join karaokestrong.reserva as rese on rese.idcliente=clie.idcliente inner join karaokestrong.sala as sal on sal.idsala=rese.idsala inner join karaokestrong.local as loc on loc.idlocal=sal.idlocal inner join karaokestrong.detallecomprobante as deta on deta.idcomprobante=comp.idcomprobante inner join karaokestrong.producto as prod on prod.idproducto=deta.idproducto where comp.fecha= ? and loc.nombre= ?";
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setTimestamp(1, fecha);
			stmt.setString(2, nombre);
			rs = stmt.executeQuery();
			
			while (rs.next()) {
				c.add(new Reportes(rs.getString("NombreS"), rs.getTimestamp("fecha"), rs.getInt("cantidad"), rs.getString("NombreP"), rs.getDouble("precio")));
			}
			rs.close();
			stmt.close();
			con.close();
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
		}
		return c;
		}
}
